package starkuz.lg.tools;

import starkuz.lg.dto.FormFieldsDto;

import java.io.*;

public class HtmlFileMaker {

    public static File getHtmlFile(FormFieldsDto dto, String path, Integer type)
            throws IOException {
        //для переходов
        String templateSrcCTR = "<!DOCTYPE html>\n" +
                "<html>\n" +
                "<head>\n" +
                "    <title>" + dto.getTitleTag() + "</title>\n" +
                "    <meta name=\"description\" content=\"" + dto.getDescripTag() + "\">\n" +
                "    <meta name=\"keywords\" content=\"" + dto.getKeywordTag() + "\">\n" +
                "    <meta name=\"viewport\" content=\"width=device-width\" />\n" +
                "    <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />\n" +
                "    <link rel=\"shortcut icon\" href=\"static/templates/templ" + dto.getIdTemplate() + "/images/favicon.ico\" />\n" +
                "    <link rel=\"stylesheet\" href=\"static/templates/templ" + dto.getIdTemplate() + "/style.css\" type=\"text/css\" media=\"all\" />\n" +
                "    <script src=\"static/js/jquery-1.7.2.min.js\" type=\"text/javascript\"></script>\n" +
                "    <script src=\"static/js/html5.js\" type=\"text/javascript\"></script>\n" +
                "    <script src=\"static/js/functions.js\" type=\"text/javascript\"></script>\n" +
                "</head>\n" +
                "<body>\n" +
                "<section id=\"wrapper\">\n" +
                "    <section id=\"bg\">\n" +
                "        <img src=\"static/templates/templ" + dto.getIdTemplate() + "/images/bg.jpg\" style=\"top: -54.375px; left: -45.5px; opacity: 1;\" alt=\"\" />\n" +
                "    </section>\n" +
                "    <!-- /#bg -->\n" +
                "\n" +
                "    <section class=\"content-box\" style=\"left:" + dto.getBlackBox() + "%;\">\n" +
                "        <h1 id=\"logo\"><a href=\"#\" class=\"notext\"></a></h1>\n" +
                "        <section class=\"blackbox\">\n" +
                "            <h1>" + dto.getMainHeader() + "</h1>\n" +
                "            <h2>" + dto.getBriefDef() + "</h2>\n" +
                "            <p>" + dto.getDopText() + "</p>\n" +
                "            <p class=\"ctrBtn\"><a href=\"http://" + dto.getGoToUrl() + "\">" + dto.getBtnTxt() + "</a></p>\n" +
                "            <a href=\"http://" + dto.getMySite() + "\" target=\"_blank\">" + dto.getCompanyName() + "</a>\n" +
                "            <p></p>\n" +
                "        </section>\n" +
                "        <!-- /.blackbox -->\n" +
                "        <footer class=\"footer\">\n" +
                "        </footer>\n" +
                "    </section>\n" +
                "    <!-- /.content-box -->\n" +
                "</section>\n" +
                "<!-- код статистики -->\n" +
                "" + dto.getStatCode() + "\n" +
                "<!-- код статистики -->\n" +
                "</body>\n" +
                "</html>";
        //для лаунчеров
        String templateSrcLaunSoon = "<!DOCTYPE html>\n" +
                "<html>\n" +
                "<head>\n" +
                "    <title>" + dto.getTitleTag() + "</title>\n" +
                "    <meta name=\"description\" content=\"" + dto.getDescripTag() + "\">\n" +
                "    <meta name=\"keywords\" content=\"" + dto.getKeywordTag() + "\">\n" +
                "    <meta name=\"viewport\" content=\"width=device-width\" />\n" +
                "    <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />\n" +
                "    <link rel=\"shortcut icon\" href=\"static/templates/templ" + dto.getIdTemplate() + "/images/favicon.ico\" />\n" +
                "    <link rel=\"stylesheet\" href=\"static/templates/templ" + dto.getIdTemplate() + "/style.css\" type=\"text/css\" media=\"all\" />\n" +
                "    <script src=\"static/js/jquery-1.7.2.min.js\" type=\"text/javascript\"></script>\n" +
                "    <script src=\"static/js/html5.js\" type=\"text/javascript\"></script>\n" +
                "    <script src=\"static/js/functions.js\" type=\"text/javascript\"></script>\n" +
                "    <script>\n" +
                "        $(document).ready(function(){\n" +
                "            $(\"#countdown\").countdown({\n" +
                "                        date: \"" + dto.getMyCount1() + " "+ dto.getMyCount2() + ":" + dto.getMyCount3() + ":" + dto.getMyCount4() + "\",   //\"09 may 2013 07:00:00\"\n" +
                "                        format: \"on\"\n" +
                "                    },\n" +
                "\n" +
                "                    function() {\n" +
                "                        // callback function\n" +
                "                    });\n" +
                "        });\n" +
                "    </script>   \n" +
                "</head>\n" +
                "\n" +
                "<body>\n" +
                "\n" +
                "<section id=\"wrapper\">\n" +
                "\n" +
                "    <div id=\"cont\">\n" +
                "\n" +
                "        <header>\n" +
                "            <p>" + dto.getAddMess() + "</p>\n" +
                "            <div class=\"clear\"></div>\n" +
                "        </header>\n" +
                "\n" +
                "        <section id=\"box\">\n" +
                "            <div class=\"arrow-up\"></div>\n" +
                "            <div id=\"box-top\">\n" +
                "                <h1>" + dto.getMainHeader() + "</h1>\n" +
                "                <p>" + dto.getDopText() + "</p>\n" +
                "\n" +
                "                <div id=\"form\">\n" +
                "                    <form method=\"post\" action=\"" + dto.getAction() + "\">\n" +
                "                     " + dto.getInputsCode() + "\n" +
                "                    </form>\n" +
                "                </div>\n" +
                "\n" +
                "            </div>\n" +
                "            <div id=\"box-bottom\">\n" +
                "\n" +
                "                <div id=\"countdown-container\">\n" +
                "                    <p class=\"launch-text\">Осталось...</p>\n" +
                "                    <div id=\"timer\">\n" +
                "                        <ul id=\"countdown\">\n" +
                "                            <li>\n" +
                "                                <span class=\"days\">00</span>\n" +
                "                                <p class=\"timeRefDays\">дней</p>\n" +
                "                            </li>\n" +
                "                            <li>\n" +
                "                                <span class=\"hours\">00</span>\n" +
                "                                <p class=\"timeRefHours\">часов</p>\n" +
                "                            </li>\n" +
                "                            <li>\n" +
                "                                <span class=\"minutes\">00</span>\n" +
                "                                <p class=\"timeRefMinutes\">минут</p>\n" +
                "                            </li>\n" +
                "                            <li>\n" +
                "                                <span class=\"seconds\">00</span>\n" +
                "                                <p class=\"timeRefSeconds\">секунд</p>\n" +
                "                            </li>\n" +
                "                        </ul>\n" +
                "                    </div>\n" +
                "                    <div class=\"clear\"></div>\n" +
                "                </div>\n" +
                "\n" +
                "            </div>\n" +
                "        </section>\n" +
                "\n" +
                "        <div id=\"footer\">\n" +
                "            <p class=\"legal\"><a href=\"http://" + dto.getMySite() + "\" target=\"_blank\">" + dto.getCompanyName() + "</a></p>\n" +
                "        </div>\n" +
                "\n" +
                "    </div>\n" +
                "</section>\n" +
                "<!-- код статистики -->\n" +
                "" + dto.getStatCode() + "\n" +
                "<!-- код статистики -->\n" +
                "</body>\n" +
                "</html>";
        //для лидов
        String templateSrcLead = "<!DOCTYPE html>\n" +
                "<html>\n" +
                "<head>\n" +
                "    <title>" + dto.getTitleTag() + "</title>\n" +
                "    <meta name=\"description\" content=\"" + dto.getDescripTag() + "\">\n" +
                "    <meta name=\"keywords\" content=\"" + dto.getKeywordTag() + "\">\n" +
                "    <meta name=\"viewport\" content=\"width=device-width\" />\n" +
                "    <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />\n" +
                "    <link rel=\"shortcut icon\" href=\"static/templates/templ" + dto.getIdTemplate() + "/images/favicon.ico\" />\n" +
                "    <link rel=\"stylesheet\" href=\"static/templates/templ" + dto.getIdTemplate() + "/style.css\" type=\"text/css\" media=\"all\" />\n" +
                "    <script src=\"static/js/jquery-1.7.2.min.js\" type=\"text/javascript\"></script>\n" +
                "    <script src=\"static/js/html5.js\" type=\"text/javascript\"></script>\n" +
                "    <script src=\"static/js/functions.js\" type=\"text/javascript\"></script>\n" +
                "</head>\n" +
                "<body>\n" +
                "<section id=\"wrapper\">\n" +
                "    <section id=\"bg\">\n" +
                "        <img src=\"static/templates/templ" + dto.getIdTemplate() + "/images/bg.jpg\" style=\"top: -54.375px; left: -45.5px; opacity: 1;\" alt=\"\" />\n" +
                "    </section>\n" +
                "    <!-- /#bg -->\n" +
                "\n" +
                "    <section class=\"content-box\" style=\"left:" + dto.getBlackBox() + "%;\">\n" +
                "        <h1 id=\"logo\"><a href=\"#\" class=\"notext\"></a></h1>\n" +
                "        <section class=\"blackbox\">\n" +
                "            <h1>" + dto.getMainHeader() + "</h1>\n" +
                "            <h2>" + dto.getBriefDef() + "</h2>\n" +
                "            <p>" + dto.getDopText() + "</p>\n" +
                "            <form method=\"post\" action=\"" + dto.getAction() + " \">\n" +
                "            " + dto.getInputsCode() + "\n" +
                "            </form>\n" +
                "            <p>Конфиденциальность данных гарантируется</p>\n" +
                "            <a href=\"http://" + dto.getMySite() + "\" target=\"_blank\">" + dto.getCompanyName() + "</a>\n" +
                "            <p></p>\n" +
                "        </section>\n" +
                "        <!-- /.blackbox -->\n" +
                "        <footer class=\"footer\">\n" +
                "        </footer>\n" +
                "    </section>\n" +
                "    <!-- /.content-box -->\n" +
                "</section>\n" +
                "<!-- код статистики -->\n" +
                "" + dto.getStatCode() + "\n" +
                "<!-- код статистики -->\n" +
                "</body>\n" +
                "</html>";


        File file = new File(path +"/index.html");
        Writer writer = new OutputStreamWriter(new FileOutputStream(file), "UTF8");

        //выбор типа шаблона lead, launSoon, ctr и т. д.
        switch (type){
            case 1: writer.write(templateSrcLead); break;
            case 2: writer.write(templateSrcLaunSoon); break;
            case 3: writer.write(templateSrcCTR); break;
        }
        writer.flush();
        writer.close();
        return file;
    }
}
